<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'menu-form',
        'enableAjaxValidation' => false,
//        'enableClientValidation' => true,
//        'clientOptions' => array(
//            'validateOnSubmit' => true,
//        ),
//        'htmlOptions' => array('enctype' => 'multipart/form-data')
            ));
    ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <div class="row buttons" align="right">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php echo $form->errorSummary($model); ?>

    <?php if (Util::user()->id == 1): ?>
        <div class="row">
            <?php echo $form->labelEx($model, 'type_id'); ?>
            <?php
            echo $form->dropDownlist($model, 'type_id', array(Menu::MAIN_MENU => 'Main Menu', Menu::ADMIN_MENU => 'Admin Menu', Menu::USER_MENU => 'User Menu'), array(
                'empty' => '- Select -',
                'ajax' => array(
                    'type' => 'POST',
                    'url' => $this->createUrl('loadDynamicType'),
                    'update' => '#Menu_parent_id',
                ),
            ));
            ?>
            <?php echo $form->error($model, 'type_id'); ?>
        </div>
    <?php else: ?>
        <?php echo $form->hiddenField($model, 'type_id', array('value'=>1)); ?>
    <?php endif; ?>

    <div class="row">
        <?php echo $form->labelEx($model, 'parent_id'); ?>
        <?php echo $form->dropDownlist($model, 'parent_id', $parent, array('size' => 10, 'style' => 'width: 220px')); ?>
        <?php echo $form->error($model, 'parent_id'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'name'); ?>
        <?php
        echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 64,
            'onkeyup' => CHtml::ajax(
                    array(
                        'type' => 'POST',
                        'url' => $this->createUrl('generateAlias'),
                        'success' =>
                        'function(html) {
                                                    $("#Menu_alias").val(html)
                                                }'
                    )
            ),
            'ajax' => array(
                'type' => 'POST',
                'url' => $this->createUrl('generateAlias'),
                'update' => '#Menu_alias',
            ),
        ));
        ?>
        <?php echo $form->error($model, 'name'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'alias'); ?>
        <?php echo $form->textField($model, 'alias', array('size' => 60, 'maxlength' => 64)); ?>
        <?php echo $form->error($model, 'alias'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'url'); ?>
        <?php echo $form->textField($model, 'url', array('size' => 60, 'maxlength' => 128)); ?>
        <?php echo $form->error($model, 'url'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'weight'); ?>
        <?php echo $form->textField($model, 'weight', array('size' => 11, 'maxlength' => 11)); ?>
        <?php echo $form->error($model, 'weight'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'visibleExpression'); ?>
        <?php echo $form->textField($model, 'visibleExpression', array('size' => 60, 'maxlength' => 155)); ?>
        <?php echo $form->error($model, 'visibleExpression'); ?>
    </div>

    <?php if (!$model->isNewRecord): ?>    
        <input type="hidden" name="update_id" value="<?php echo $model->id; ?>"/>
    <?php endif; ?>     
        
    <div class="row buttons" align="right">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->